﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace ToDoList.Logic
{
    public class ManageDetailedList
    {
        public bool CreatDetailedList(string listName,int userId)
        {
            int listId = DataSource.detailedLists.Max(a => a.ListID) + 1;
            //var list = DataSource.detailedLists.SingleOrDefault(a => a.ListID == listId);
            var user = DataSource.users.SingleOrDefault(a => a.UserID == userId);
            if (user != null)
            {
                DataSource.detailedLists.Add(
                    new DetailedList { ListID = listId, Time = DateTime.Now, NameOfList = listName });
                user.detailedLists = new List<DetailedList>();
                user.detailedLists.Add(
                    new DetailedList { ListID = listId, Time = DateTime.Now, NameOfList = listName });
                //user.detailedLists.Select(a => a.User.UserID = userId);
                return true;
            }
            else
                return false;
        }

        public bool ModifyListName(int listId,string newListName)
        {
            var list = DataSource.detailedLists.SingleOrDefault(a => a.ListID == listId);
            if (list != null)
            {
                list.NameOfList = newListName;

                return true;
            }
            else
                return false;
        }

        public List<DetailedList> ViewAllDetailedList(int uerId)
        {
            var user = DataSource.users.SingleOrDefault(a => a.UserID == uerId);
            if (user != null)
            {
                return user.detailedLists;
            }
            else
                return null;
        }




        
    }
}
